<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        * {
            margin: 0;
            padding: 0;
        }

        ul {
            list-style: none;
        }

        img {
            display: block;
        }

        body {
            padding-top: 100px;
        }

        .tab {
            width: 500px;
            margin: auto;
            border-top: 1px solid #ccc;
        }

        .tabs {
            display: flex;
        }

        .tabs li {
            padding: 10px 20px;
            transform: translateY(-1px);
            cursor: pointer;
            border-top: 2px solid transparent;
        }

        .tabs li.current {
            border-top: 2px solid #d50;
        }

        .contents li {
            display: none;
        }

        .contents li.show {
            display: block;
        }
    </style>
</head>

<body>
    <div class="tab">
        <ul class="tabs">
            <li class="current">要闻</li>
            <li>广州 新闻</li>
            <li>军事 | 航天</li>
        </ul>
        <ul class="contents">
            <li class="show"><img src="./images/tabs/1.png" alt=""></li>
            <li><img src="./images/tabs/2.png" alt=""></li>
            <li><img src="./images/tabs/3.png" alt=""></li>
        </ul>
    </div>
    <script>
        let tabs = document.querySelectorAll('.tabs li')
        let contents = document.querySelectorAll('.contents li')
        tabs.forEach((item, index) => {
            item.onclick = function () {
                tabs.forEach(tab => tab.classList.remove('current'))
                this.classList.add('current')
                contents.forEach(c => c.classList.remove('show'))
                contents[index].classList.add('show')
            }
        })
    </script>
</body>

</html>